<template>
<div class="layerRtb layerRtb-threecolumn">
    <three-title :title="{name:'设置'}"></three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "84">
        <div class="analyItem">
                <p class="analyItemTit tx-center">标准</p>
                <div class="analyItemCon">
                    <div class="clearfix mb5">
                        <p class="fl col-md-9"><input v-model="sdTitle" type="text" placeholder="标题" class="col-md-11" name="saveStandardTitle">
                        </p>
                        <p class="col-md-3">
                            <select v-model="stId" class="col-md-12 fr" name="saveStandardStage">
                                <option value="">-请选择阶段-</option>
                                <option value="1">咨询</option>
                                <option value="2">认知</option>
                                <option value="3">考察</option>
                                <option value="4">签约</option>
                            </select>
                        </p>
                    </div>
                    <p class="fl col-md-12 mb5">
                        <textarea v-model="cdContent" rows="2" placeholder="内容" class="assessment-textarea col-md-12" name="saveStandardContent"></textarea>
                    </p>
                    <p class="fl col-md-6 mb5">
                        <span class="fl">优：</span>
                        <input v-model="stYou" type="text" class="col-md-10" name="saveStandardYou">
                    </p>
                    <p class="fl col-md-6 mb5">
                        <span class="fl">良：</span>
                        <input v-model="stLiang" type="text" class="col-md-10" name="saveStandardLiang">
                    </p>
                    <p class="fl col-md-6 mb5">
                        <span class="fl">中：</span>
                        <input v-model="stZhong" type="text" class="col-md-10" name="saveStandardZhong">
                    </p>
                    <p class="fl col-md-6 mb5">
                        <span class="fl">差：</span>
                        <input v-model="stCha" type="text" class="col-md-10" name="saveStandardCha"></p>
                    <p class="fl col-md-12 mb5 tx-center">
                        <input @click="saveStandard" type="button" value="确定" class=" uiBtn-blue uiBtn-small" style="margin-top: 20px; margin-left: 30px;" name="saveStandard">
                    </p>
                </div>
        </div>
        <div class="analyItem" v-for="(item,index) in pmStandards" :key="index">
            <p class="analyItemTit tx-center">标准</p>
            <div class="analyItemCon" v-if="flg==0 && sdId === item.sdId">
                <div class="clearfix">
                    <p class="fl col-md-8 mb5"><input v-model="upSdTitle" type="text" placeholder="标题" class="col-md-11" name="updateStandardTitle">
                    </p>
                    <p class="col-md-2">
                        <select v-model="upStId" class="col-md-12 fr" name="updateStandardStage">
                            <option value="">-请选择阶段-</option>
                            <option value="1">咨询</option>
                            <option value="2">认知</option>
                            <option value="3">考察</option>
                            <option value="4">签约</option>
                        </select>
                    </p>
                </div>
                <p class="fl col-md-12 mb5">
                    <textarea v-model="upCdContent" rows="2" placeholder="内容" class="assessment-textarea col-md-12" name="updateStandardContent"></textarea>
                </p>
                <p class="fl col-md-6 mb5">
                    <span class="fl">优：</span>
                    <input v-model="upStYou" type="text" class="col-md-10" name="updateStandardYou">
                </p>
                <p class="fl col-md-6 mb5">
                    <span class="fl">良：</span>
                    <input v-model="upStLiang" type="text" class="col-md-10" name="updateStandardLiang">
                </p>
                <p class="fl col-md-6 mb5">
                    <span class="fl">中：</span>
                    <input v-model="upStZhong" type="text" class="col-md-10" name="updateStandardZhong">
                </p>
                <p class="fl col-md-6 mb5">
                    <span class="fl">差：</span>
                    <input v-model="upStCha" type="text" class="col-md-10" name="updateStandardCha"></p>
                <div class="imgbox imgbox2 " style="margin-top: 15px; position: absolute; right: 10px;top: 5px;">
                    <img src="https://gnr.rxjy.com/hrms/static/modules/cur/images/save_img.png" title="保存" width="20" class="fl pointer mr5" name="update_stage_info_intention" @click="updateStandard()">
                    <img src="https://gnr.rxjy.com/hrms/static/modules/cur/images/goback_img.png" title="返回" width="20" class="fl pointer mr5" @click="flg=1">
                </div>
            </div>
            <div class="analyItemCon" v-else>
                <p class="fl col-md-12">
                    <span class="cLightGray pr8">标题</span>
                    <span class="c999999">{{item.sdTitle}}</span></p>
                <p class="fl col-md-12">
                    <span class="cLightGray pr8">内容</span>
                    <span class="c999999">{{item.cdContent}}</span></p>
                <p class="fl col-md-12">
                    <label class="col-md-6">优：{{item.stYou}}
                        <span class="c999999 ml10">({{item.stYouScore}}分)</span></label>
                    <label class="col-md-6">良：{{item.stLiang}}
                        <span class="c999999 ml10">({{item.stLiangScore}}分)</span></label>
                    <label class="col-md-6">中：{{item.stZhong}}
                        <span class="c999999 ml10">({{item.stZhongScore}}分)</span></label>
                    <label class="col-md-6">差：{{item.stCha}}
                        <span class="c999999 ml10">({{item.stChaScore}}分)</span></label>
                </p>
                <p><span class="roleFixed" style="color: #85da02;float: right;">{{item.stId | jieduan}}</span></p>
                <div class="imgbox imgbox1 col-md-2" style="margin-top: 15px; position: absolute; right: 10px;top: 10px;">
                    <img src="https://proj01.oss-cn-beijing.aliyuncs.com/worker/1582078336kn4XDPDSP0kpAj6YDzCNzzzd.png" title="删除" width="20" class="fr pointer mr5" @click="deleteStandard(item.sdId)">
                    <img src="https://gnr.rxjy.com/hrms/static/modules/cur/images/edit_img.png" title="编辑" width="20" class="fr pointer mr5" @click="updateFlg(item, flg)">
                </div>
            </div>
       </div>
     </div>

                    <div class="analyItem">
                    <p class="analyItemTit tx-center">综合</p>
                    <div class="analyItemCon">

                    </div>
                </div>
        </div>
</template>
<script>
import {mapGetters} from 'vuex'
import {saveStandard, getPmStandardList, deleteStandard, updateStandard} from '../../Resources/Api/index'
export default {
    data () {
        return {
            flg: 1,
            stId: 0,
            sdTitle: '',
            cdContent: '',
            stYou: '',
            stLiang: '',
            stZhong: '',
            stCha: '',
            pmStandards: [],
            sdId: 0,
            upStId: 0,
            upSdTitle: '',
            upCdContent: '',
            upStYou: '',
            upStLiang: '',
            upStZhong: '',
            upStCha: ''
        }
    },
    created () {
        this.getPmStandardList()
    },
    computed: {
        ...mapGetters(['leftInfo'])
    },
    methods: {
        deleteStandard (value) {
            deleteStandard({
                sdId: Number(value)
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    layer.msg('删除成功')
                    this.getPmStandardList()
                    // this.setUpdatePlate()
                }
            })
        },
        updateStandard () {
            updateStandard({
                sdId: this.sdId,
                stId: this.upStId,
                sdTitle: this.upSdTitle,
                cdContent: this.upCdContent,
                stYou: this.upStYou,
                stLiang: this.upStLiang,
                stZhong: this.upStZhong,
                stCha: this.upStCha
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    layer.msg('修改成功')
                    this.updateFlg('', 0)
                    this.getPmStandardList()
                    // this.setUpdatePlate()
                }
            })
        },
        updateFlg (value, upFlg) {
            if (Number(upFlg) === 1) {
                this.flg = 0
                // debugger
                // console.log(value)
                this.sdId = value.sdId
                this.upStId = value.stId
                this.upSdTitle = value.sdTitle
                this.upStZhong = value.stZhong
                this.upCdContent = value.cdContent
                this.upStYou = value.stYou
                this.upStLiang = value.stLiang
                this.upStCha = value.stCha
            } else if (Number(upFlg) === 0) {
                this.flg = 1
                this.sdId = 0
                this.upStId = 0
                this.upSdTitle = ''
                this.upStZhong = ''
                this.upCdContent = ''
                this.upStYou = ''
                this.upStLiang = ''
                this.upStCha = ''
            }
        },
        getPmStandardList () {
            getPmStandardList({
                stId: this.leftInfo.stId
            }).then(res => {
                if (res.data.StatusCode === 0) {
                    this.pmStandards = res.data.Body.pmStandards
                }
            }).catch(err => {
                console.log(err)
            })
        },
        saveStandard () {
            saveStandard({
                stId: this.stId,
                sdTitle: this.sdTitle,
                cdContent: this.cdContent,
                stYou: this.stYou,
                stLiang: this.stLiang,
                stZhong: this.stZhong,
                stCha: this.stCha
            }).then(res => {
                if (res.data.StatusCode === 0) {
                    layer.msg('添加标准成功')
                    this.sdTitle = ''
                    this.cdContent = ''
                    this.stYou = ''
                    this.stLiang = ''
                    this.stZhong = ''
                    this.stCha = ''
                    this.getPmStandardList()
                    // this.setUpdatePlate()
                }
            }).catch(err => {
                console.log(err)
            })
        }

    },
    filters: {
        jieduan: function (data) {
            if (data === 1) {
                return '咨询'
            } else if (data === 2) {
                return '认知'
            } else if (data === 3) {
                return '考察'
            } else if (data === 4) {
                return '签约'
            }
        }
    },
    watch: {
    }
}
</script>

